package ch5.CountDownLatchCase;

import util.Debug;
import util.Tools;

import java.awt.*;
import java.util.concurrent.CountDownLatch;

/**
 * 一个线程多次执行CountDownLatch.countDown示例
 */

public class CountDownLatchExample {
    private static final CountDownLatch latch = new CountDownLatch(4);
    private static int data;

    public static void main(String[] args) throws InterruptedException {
        Thread workerThread = new Thread() {
            @Override
            public void run() {
                for (int i = 1; i < 10; i++) {
                   data = i;
                   latch.countDown();
                    Tools.randomPause(1000);
                }
            }
        };
        workerThread.start();
        latch.await();
        Debug.info("It's done. data = %d", data);
    }
}
